package lockDemo.synchronizeDemo;

/**
 * @Author: Jie
 * @Date: 2019/5/19 17:28
 * @Function :测试 sync Class.this
 */
public class SyncClass {
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    methoda();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    methodb();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private synchronized static void methoda() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            Thread.sleep(200);
            System.out.println("aaaaaa");
        }
    }

    private synchronized static void methodb() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            Thread.sleep(200);
            System.out.println("bbbbbbbbbbbbbbbbbbbbbb");
        }
    }


}
